#include "../../../odb/user.hxx"
#include "user-odb.hxx"
#include "../../../common/data_mysql.hpp"
#include "gflags/gflags.h"

DEFINE_bool(run_mode, false, "程序的运行模式，false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void insert(zjx_im::UserTable &user)
{
    auto user1 = std::make_shared<zjx_im::User>("uid1", "昵称1", "123456");
    user.insert(user1);
    auto user2 = std::make_shared<zjx_im::User>("uid2", "1556667777");
    user.insert(user2);
}

void select_by_id(zjx_im::UserTable &user_tb)
{
    auto user = user_tb.select_by_id("uid1");
    user->description("嘻嘻嘻");
    user_tb.update(user);
}

void select_by_phone(zjx_im::UserTable &user_tb)
{
    auto user = user_tb.select_by_phone("1556667777");
    user->password("987654321");
    user_tb.update(user);
}

void select_by_nickname(zjx_im::UserTable &user_tb)
{
    auto user = user_tb.select_by_nickname("uid2");
    user->nickname("uid3");
    user_tb.update(user);
}

void select_users(zjx_im::UserTable &user_tb)
{
    std::vector<std::string> id_list = {"uid1", "uid2"}; 
    auto res = user_tb.select_multi_users(id_list);
    for(auto user : res)
    {
        std::cout << user.user_id() << std::endl;
    }
}

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    zjx_im::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);
    auto db = zjx_im::ODBFactory::create("root", "caocao123", "127.0.0.1", "zjx_im", "utf8", 0, 1);
    zjx_im::UserTable user(db);
    //insert(user);
    //select_by_id(user);
    //select_by_phone(user);
    //select_by_nickname(user);
    select_users(user);
    return 0;
}
